﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Xml.Linq;

namespace OntoWPFSilverlight.Widget
{
    [OntoWPFSilverlight.Annotation.Widget("ListBox")]
    public class Listbox : WidgetCanvas, Interfaces.IWidgetWithItems
    {
        private System.Windows.Controls.ListBox myListBox = null;
        private TextBlock label = null;
 
        public Listbox() : base()
        {
            Build();            
        }

        

        private void Build()
        {
            /*Border be = new Border();
            be.HorizontalAlignment = HorizontalAlignment.Stretch;
            be.VerticalAlignment = VerticalAlignment.Stretch; 
            */
            /*StackPanel stackpanel = new StackPanel();*/
            myListBox = new System.Windows.Controls.ListBox();
            label = new TextBlock();
            
            //label.HorizontalAlignment = HorizontalAlignment.Stretch;
            DockPanel.SetDock(label, Dock.Top);
            DockPanel.SetDock(myListBox, Dock.Top);
            this.Children.Add(label);
            this.Children.Add(myListBox);
            
            //be.Child = stackpanel;
            //this.Children.Add(be);
            //this.Width = this.WidgetSize.Width;
            //this.Height = this.WidgetSize.Height;
            //Canvas.SetLeft(this, this.WidgetLocation.Y);
            //Canvas.SetTop(this, this.WidgetLocation.X);
           
        }


        public override string Text
        {
            get
            {
                return this.label.Text;
            }
            set
            {
                //System.Windows.Browser.HtmlPage.Window.Alert("listbox" + value);
                this.label.Text = value;
            }
        }

        #region IWidgetWithItems Membri di

        OntoWPFSilverlight.Node ontologyNode;
        public OntoWPFSilverlight.Node Node
        {
            get
            {
                return ontologyNode;
            }
            set
            {
                ontologyNode = value;
            }
        }

        OntoWPFSilverlight.Xml.OntologiesNodes ontologiesNodes = null;
        public OntoWPFSilverlight.Xml.OntologiesNodes OntologiesNodes
        {
            get
            {
                return ontologiesNodes;
            }
            set
            {
                this.ontologiesNodes = value;
            }
        }
        
        public void update(List<Node> nodes)
        {
            foreach (Node _node in nodes)
            {
                
                myListBox.Items.Add(_node.Alias);
                
            }
        }

        #endregion

        #region IWidgetWithItems Membri di


        public void update()
        {
            update(this.ontologiesNodes.Nodes);
        }

        #endregion
    }
}
